﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:admininfo
	/// </summary>
	public partial class admininfo
	{
		public admininfo()
		{}
		#region  Method
        public int AdminLogin(string name, string pwd, int atid)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					
					new SqlParameter("@aname", SqlDbType.VarChar,15),
					new SqlParameter("@apwd", SqlDbType.VarChar,20),
					new SqlParameter("@atid", SqlDbType.Int,4)};
            parameters[0].Value = name;
            parameters[1].Value = pwd;
            parameters[2].Value = atid;
            return DbHelperSQL.RunProcedure("P_AdminLogin", parameters, out rowsAffected);

        }
		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("aid", "admininfo"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int aid)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@aid", SqlDbType.Int,4)};
			parameters[0].Value = aid;

			int result= DbHelperSQL.RunProcedure("admininfo_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public bool Add(lcmyjobs.Model.admininfo model)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@aid", SqlDbType.Int,4),
					new SqlParameter("@aname", SqlDbType.VarChar,15),
					new SqlParameter("@apwd", SqlDbType.VarChar,20),
					new SqlParameter("@atid", SqlDbType.Int,4),
                    new SqlParameter("@truename", SqlDbType.VarChar,20)};
			parameters[0].Value = model.aid;
			parameters[1].Value = model.aname;
			parameters[2].Value = model.apwd;
			parameters[3].Value = model.atid;
            parameters[4].Value = model.truename;

			DbHelperSQL.RunProcedure("admininfo_ADD",parameters,out rowsAffected);
            if (rowsAffected == 1)
                return true;
            else
                return false;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.admininfo model)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@aid", SqlDbType.Int,4),
					new SqlParameter("@aname", SqlDbType.VarChar,15),
					new SqlParameter("@apwd", SqlDbType.VarChar,20),
					new SqlParameter("@atid", SqlDbType.Int,4),
                    new SqlParameter("@truename", SqlDbType.VarChar,20)};
			parameters[0].Value = model.aid;
			parameters[1].Value = model.aname;
			parameters[2].Value = model.apwd;
			parameters[3].Value = model.atid;
            parameters[4].Value = model.truename;

			DbHelperSQL.RunProcedure("admininfo_Update",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int aid)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@aid", SqlDbType.Int,4)};
			parameters[0].Value = aid;

			DbHelperSQL.RunProcedure("admininfo_Delete",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string aidlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from admininfo ");
			strSql.Append(" where aid in ("+aidlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.admininfo GetModel(int aid)
		{
            SqlParameter[] parameters = {
					new SqlParameter("@aid", SqlDbType.Int,4)
};
            parameters[0].Value = aid;

            lcmyjobs.Model.admininfo model = new lcmyjobs.Model.admininfo();
            DataSet ds = DbHelperSQL.RunProcedure("admininfo_GetModel", parameters, "ds");
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["aid"] != null && ds.Tables[0].Rows[0]["aid"].ToString() != "")
                {
                    model.aid = int.Parse(ds.Tables[0].Rows[0]["aid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["aname"] != null && ds.Tables[0].Rows[0]["aname"].ToString() != "")
                {
                    model.aname = ds.Tables[0].Rows[0]["aname"].ToString();
                }
                if (ds.Tables[0].Rows[0]["apwd"] != null && ds.Tables[0].Rows[0]["apwd"].ToString() != "")
                {
                    model.apwd = ds.Tables[0].Rows[0]["apwd"].ToString();
                }
                if (ds.Tables[0].Rows[0]["atid"] != null && ds.Tables[0].Rows[0]["atid"].ToString() != "")
                {
                    model.atid = int.Parse(ds.Tables[0].Rows[0]["atid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["truename"] != null && ds.Tables[0].Rows[0]["truename"].ToString() != "")
                {
                    model.truename = ds.Tables[0].Rows[0]["truename"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select aid,aname,apwd,atid ");
			strSql.Append(" FROM admininfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" aid,aname,apwd,atid ");
			strSql.Append(" FROM admininfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "admininfo";
			parameters[1].Value = "aid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

